package sdk8.threadsyUse.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池（一）1、使用newCachedThreadPool
 * @className: ThreadPools1
 * @author: junjie
 * @date: 2022-08-19 17:39
 */
public class ThreadPools1 {
    //1、使用newCachedThreadPool
    public static void main(String[] args) throws InterruptedException {
        ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            final int index = i;
            Thread.sleep(index * 1000);
            cachedThreadPool.execute(new Runnable() {
                public void run() {
                    System.out.println(index);
                }
            });
        }

    }
}
